package de.jmda.gen.java.impl;

import static de.jmda.util.StringUtil.sb;
import de.jmda.gen.GeneratorException;
import de.jmda.gen.impl.DefaultGenerator;
import de.jmda.gen.java.ImplementsClauseGenerator;
import de.jmda.util.StringUtil;

/**
 * @author roger.jmda@gmail.com
 */
public class DefaultImplementsClauseGenerator
		extends DefaultGenerator
		implements ImplementsClauseGenerator
{
	public DefaultImplementsClauseGenerator()
  {
	  super();
  }

	public DefaultImplementsClauseGenerator(String input)
  {
	  super(input);
  }

	@Override
  public StringBuffer generate() throws GeneratorException
  {
		StringBuffer result = super.generate();
		
		if (false == StringUtil.isBlank(result))
		{
			String prefix = "implements ";

			if (false == StringUtil.startsWith(result, prefix))
			{
				result = sb(prefix).append(result);
			}
		}
		
		return result;
  }

	@Override
  public StringBuffer getImplementsClause() throws GeneratorException
  {
	  return generate();
  }

	@Override
  public void setImplementsClause(StringBuffer implementsClause)
  {
		setOutput(implementsClause);
  }

	@Override
  public void setImplementsClause(String implementsClause)
  {
		setImplementsClause(sb(implementsClause));
  }
}